<?php
function printID()
{
    fprintf(STDOUT,"pid=%d\n",posix_getpid());
    fprintf(STDOUT,"ppid=%d\n",posix_getppid());
    fprintf(STDOUT,"pgid=%d\n",posix_getpgrp());
    fprintf(STDOUT,"sid=%d\n",posix_getsid(posix_getpid()));
    fprintf(STDOUT,"uid=%d\n",posix_getuid());
    fprintf(STDOUT,"gid=%d\n",posix_getgid());
    fprintf(STDOUT,"euid=%d\n",posix_geteuid());
    fprintf(STDOUT,"egid=%d\n",posix_getegid());
}


$text = "php is the best language";
fprintf(STDOUT,"现在我的标识是:pid=%d\n",posix_getpid());
$pid = pcntl_fork();
if ($pid==0){
    fprintf(STDOUT,"pid=%d 我是子进程，我开始运行了.\n",posix_getpid());
    fprintf(STDOUT,"child process:xpid=%d\n",$pid,$text);
}else{
    sleep(2);
    fprintf(STDOUT,"pid=%d 我是父进程,我睡了2秒才打印\n",posix_getpid());
    fprintf(STDOUT,"father process:xpid=%d,text=%s\n",$pid,$text);
}
fprintf(STDOUT,"pid=%d,ppid=%d,run here.\n",posix_getpid(),posix_getppid());